package com.learn.xueer.ui.viewmodel

import com.learn.xueer.app.network.apiService
import com.learn.xueer.data.model.bean.QuestionBean
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.IntObservableField
import me.hgj.jetpackmvvm.ext.request

class PkAnswerViewModel : BaseViewModel() {

    val scoreFirst = IntObservableField(0)
    val scoreSecond = IntObservableField(0)

    fun submitAnswer(id: String, wid: String, pkId: String) {
        request(
            { apiService.submitAnswer(id, wid, pkId) }, {}, {}, false
        )
    }

    fun updateScore(questionBean: QuestionBean) {
        if (questionBean.hasAnswer == 1) {
            scoreFirst.set(1 + scoreFirst.get())
        }
        if (questionBean.otherAnswer == 1) {
            scoreSecond.set(1 + scoreSecond.get())
        }
    }
}